home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4143 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. Path: newspost1.alt.net!usenet
  2. From: walth@netcom.com (Walt Howard)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: weird behavior
  5. Date: Sun, 28 Jan 1996 12:25:23 GMT
  6. Organization: AltNet - Affordable Usenet Access - http://www.alt.net
  7. Message-ID: <4efpvs$elb@tofu.alt.net>
  8. References: <4ed10l$jap@news.csus.edu>
  9. Reply-To: walth@netcom.com
  10. X-Newsreader: Forte Agent .99c/32.126
  11.  
  12. On 27 Jan 1996 11:07:01 GMT, gustavo.sandoval@csus.edu (gustavo
  13. sandoval) wrote:
  14.  
  15. >I have the following linked list which I'm playing around with:
  16. >
  17. >class CList
  18. >{
  19. >public:
  20. >   CList(); 
  21. >   ~CList();
  22. >
  23. >   void Insert(int element);
  24. >   void Print ();
  25. >
  26. >   // Returns the number or items deleted
  27. >   int  Delete(int target);
  28. >   
  29. >private:
  30. >   CItem* head;
  31. >
  32. >};// CList
  33. >
  34. >// Implementation of the functions omitted 
  35. >
  36. >// In main I have:
  37. >
  38. >void main ()
  39. >{
  40. >   CList MyList;
  41. >
  42. >   for (int x = 0; x < 10; x++ )
  43. >      MyList.Insert (x*10);
  44. >
  45. >   MyList.Print();
  46. >
  47. >   int count = MyList.Delete (40);
  48. >
  49. >   MyList.Insert (50);
  50. >   MyList.Insert;           // <== this lines
  51. >   MyList.Print;            // <== this lines
  52. >
  53. >   count = MyList.Delete (50);
  54. >
  55. >}
  56. >
  57. >
  58. >note the lines with the arrows.  The code compiles in VC 4.0 without warnings 
  59. >in level 4 or errors.  When I step through those two lines the debugger just 
  60. >goes right by.  
  61. >
  62.  
  63. Well, I should really try to compile this but it's getting later. The
  64. function names by themselves might be considered valid expressions
  65. (pointers) and then the compiler is optimizing them out because they
  66. aren't doing anything. But what do I know?
  67.  
  68. >Also I looked at the disassembly and I have the following:
  69. >
  70. >181:     MyList.Insert (50);
  71. >00401541   push      00000032
  72. >00401543   lea       ecx,dword ptr [MyList]
  73. >00401546   call      @ILT+10(?Insert@CList@@QAEXH@Z) (0040100a)
  74. >182:     MyList.Insert;
  75. >183:     MyList.Print;
  76. >184:
  77. >185:     count = MyList.Delete (50);
  78. >0040154b   push      00000032
  79. >0040154d   lea       ecx,dword ptr [MyList]
  80. >00401550   call      @ILT+65(?Delete@CList@@QAEHH@Z) (00401041)
  81. >00401555   mov       dword ptr [count],eax
  82. >
  83. >
  84. >It just seems that the compiler is inserting no-ops.  Is this the right 
  85. >behavior.  To me this seems like a bug that the compiler is not catching, but 
  86. >then what do I know.
  87. >
  88. >thanks in advance,
  89. >
  90. >gustavo
  91. >
  92.  
  93.  
  94.